package br.ufmg.ubicomp.droidguide.eventservice;

import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.SAXException;

import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class EventNotificationService extends android.app.Service{
	
	public static final String BASE_URL = "http://droidguide.appspot.com/eventservice/process?";

//	public void sendEvent(String dgKey, String type, String source, String data) throws ClientProtocolException, IOException, ParserConfigurationException, FactoryConfigurationError, SAXException
//	{
//		String url = BASE_URL + "operation=save&droidGuideUser_key="+dgKey+"&type="+type+"&source="+source+"&data=" + data;
//		/* Make request */
//		DefaultHttpClient client = new DefaultHttpClient();
//		HttpGet method = new HttpGet(url);		
//		HttpResponse response =  client.execute(method);
//		HttpEntity entity = response.getEntity();
//		InputStream inStream = entity.getContent();
//		
//		/* Parse XML */
//		
//		DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//		Document doc = docBuilder.parse(inStream);
//		// root element.
//		Element root = doc.getDocumentElement();		
//		NodeList children = root.getChildNodes();
//				
//		
//		for (int i = 0; i < children.getLength(); i++) {
//			Node child = children.item(i);
//			
//			if (child instanceof Element) {
//				Element childElement = (Element) child;
//				Text textNode = (Text) childElement.getFirstChild();
//				String text = textNode.getData().trim();
//				System.out.println(childElement.getTagName());
//			}
//		}
//		
//	}

	
	
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
    @Override
    public void onCreate() {
      super.onCreate();
	  Log.d( getClassName(),"onCreate" );
    }
    
	private String getClassName() {
		return this.getClass().getSimpleName();
	}

    @Override
    public void onDestroy() {
	  super.onDestroy();
	  Log.d( getClassName(),"onDestroy" );
    }
	
}